// import { Game_Model } from "../../constants/play_def";
import PlayData from '../data/PlayData'

cc.Class({
    extends: cc.Component,

    properties: {
    },
    start_app() {
        if (window.gg) {
            he.error("重复加载主脚本")
            // 提示加载错误 游戏弹出
            return
        }
        this.initProp()         // 额外属性
        this.initComponent()    // 额外组件
        this.switch_event()     // 前后台切换暂停
        // // 初始化
        // // 要获得用户之后才进行初始化
        // // 绑定节点至更目录
        cc.game.addPersistRootNode(this.node);
        // 中心脚本改为gg
        window.gg = this
        gg.data.isManHua = false

    },
    // 前后台切换状态
    switch_event() {
        cc.game.on(cc.game.EVENT_HIDE, (event) => {
            he.log("切换后台", event);
            he.user.saveInfo()   // 用户存档储存
            he.local.saveOperation()
            cc.game.pause()
        });
        cc.game.on(cc.game.EVENT_SHOW, (event) => {
            he.log("切换前台");
            cc.game.resume()
        });
    },
    initProp() {
        this.data = new PlayData()
    },
    initComponent() {
        this.redManager = this.getComponent("redManager")
        this.redManager.initInfo()
        this.uiManager = this.getComponent("uiManager")
        this.uiManager.initInfo()
        this.eventManager = new cc.EventTarget();
        if (common.comicGuide) {
            this.eventManager.on('newGuide', this.checkGuide, this)
        }
    },


    checkGuide(param) {
        // console.log('收到信息')
        let index = param.index
        let guideCtl = this.node.getComponent('guideCtl')
        guideCtl.loadPrefab()
        guideCtl.runTask2(index)
    },

});
